<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class ChangePassword extends MY_Controller {

	function __construct()
    {
		// Call the Model constructor
        parent::__construct();
		if($this->session->userdata('login') === TRUE){
			$log['activity']='VIEW';
			$log['information']='Masuk ke menu : '.$this->uri->uri_string();
			$this->model_log->add($log);
		}else{
			$log['activity']='VIEW';
			$log['information']='Tidak diijinkan : '.$this->uri->uri_string();
			$this->model_log->add($log);
			redirect('sessions/login');
		}
    }
	
	public function index()
	{
		$this->load->model("user/model_user");
		
		if(isset($_POST['data'])){
			$data = $_POST['data'];
			$check = false;
			if($this->model_user->check_password($_POST['password'])){
				$check = true;
			}else{
				$check = false;
				$this->session->set_flashdata('error','Password Anda tidak sesuai.');
			}
			
			if($check){
				$id_user = $this->session->userdata("id_user");

				$data['password'] = sha1($data['password']);
				
				$this->model_user->edit($id_user,$data);
			}
			
			redirect("changePassword");
		}
		
		$params['content']= $this->load->view('form','',TRUE);
		$params['footer']['js_plugin'] = $this->load->view('js_plugin','',TRUE);
		$params['footer']['js_init'] = $this->load->view('js_list_init','',TRUE);
		$params['header']['css_plugin'] = $this->load->view('css_plugin','',TRUE);
		
		echo modules::run('template', $params);	
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */